﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;

namespace DAO
{
    public class nhanvien_DAO
    {
        public static DataSet loadthongtinnhanvienvaolistview()
        {
            string sql = "select manv,tennv,diachi,gioitinhnv,sdtnv,loainv,ngaysinh,cmnd,tendangnhap,mk from nhanvien";
            DataSet ds = new DataSet();
            ds = dataconnect.laydulieu(sql);
            return ds;
        }
        public static DataSet timkiemnhanvien(nhanvien_DTO nv)
        {
            string sql = "select * from nhanvien where tennv like '%"+nv.tennv+"%'";
            DataSet ds = new DataSet();
            ds = dataconnect.laydulieu(sql);
            return ds;
        }
        public static DataSet automa()
        {
            string sql = "select top 1 manv from nhanvien order by manv desc";
            DataSet ds = new DataSet();
            ds = dataconnect.laydulieu(sql);
            return ds;
        }
        public static bool themnhanvien(nhanvien_DTO nv)
        {
            string sql = "insert into nhanvien(manv,tennv,diachi,sdtnv,gioitinhnv,loainv,ngaysinh,cmnd,tendangnhap,mk) values('"+nv.manv+"','"+nv.tennv+"','"+nv.diachi+"','"+nv.sdtnv+"','"+nv.gioitinhnv+"','"+nv.loainv+"','"+nv.ngaysinh+"',"+nv.cmnd+",'"+nv.tendangnhap+"','"+nv.mk+"')";
            return dataconnect.xulycaulenh(sql);
        }
        public static bool xoanhanvien(nhanvien_DTO nv)
        {
            string sql = "delete from nhanvien where manv='"+nv.manv+"'";
            return dataconnect.xulycaulenh(sql);
        }
        public static bool suanhanvien(nhanvien_DTO nv)
        {
            string sql = "update nhanvien set tennv='"+nv.tennv+"',diachi='"+nv.diachi+"',sdtnv='"+nv.sdtnv+"',gioitinhnv='"+nv.gioitinhnv+"',loainv='"+nv.loainv+"',ngaysinh='"+nv.ngaysinh+"',cmnd="+nv.cmnd+",tendangnhap='"+nv.tendangnhap+"',mk='"+nv.mk+"' where manv='"+nv.manv+"'";
            return dataconnect.xulycaulenh(sql);
        }
    }
}
